import React,{useState} from 'react'
import useReducer from './useReducer'
function reducer(state,action){
  switch(action.type){
    case "increase":
      return state + 1;
    case "decrease" :
      return state - 1;
      default:
        return false;
  }
}
// function useReducer(){
//   const [n, setn] = useState(0)
//   const dispatch = (action)=>{
//     const newN = reducer(n,action)
//     setn(newN)
//   }
//   return {
//     n,
//     dispatch
//   }
// }
export default function App() {
  const [n,dispatch] = useReducer(reducer,0)
  return (
    <div>
        <button 
      onClick={
        ()=>{
          dispatch({type:'decrease'})
        }
      }
      >减少</button>
      <span>{n}</span>
      <button 
      onClick={
        ()=>{
          dispatch({type:'increase'})
        }
      }
      >增加</button>
    </div>
  )
}
